<?php

declare(strict_types=1);

namespace App\Chat\Amqp\Consumer;

use App\Chat\Service\Message\SubscribeHandleService;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use PhpAmqpLib\Message\AMQPMessage;
use Hyperf\Amqp\Result;

#[Consumer(exchange: "ws_route", routingKey: "ws_route", queue: "ws_queue", nums: 1, enable: true)]
class WebSocketConsumer extends ConsumerMessage
{
    public function consumeMessage($data, AMQPMessage $message): Result
    {
        if (empty($data)) {
            return Result::DROP;
        }
        stdout_log()->info('websocket消费消息');
        di()->get(SubscribeHandleService::class)->handle($data);
        return Result::ACK;
    }

    public function isEnable(): bool
    {
        return \Hyperf\Support\env('WS_CONSUMER_ENABLE', true);
    }
}